﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebEntities;
using WebsiteUI.Extensions;
using com.subb.WebInformation;
using Tools.com.Pager;
using WebEntities.Models.WebInfo;
using WebsiteUI.ActionFilters;

namespace WebsiteUI.Controllers
{
    /// <summary>
    /// 会员留言 栏目
    /// </summary>
    public class LeaveMsgController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.MenuItemID = CommonFn.GetContentID("LeaveMsgMuItemID");
            WI_LeaveMsgTypeDAL typeDal = new WI_LeaveMsgTypeDAL();
            ViewBag.LeaveTypeList = typeDal.GetAllMsgType();
            return View();
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Index(LeaveMsg obj)
        {
            ViewBag.MenuItemID = CommonFn.GetContentID("LeaveMsgMuItemID");
            var rr = Request["NeedContact"].ToString() == "1" ? true : false;
            obj.NeedContact = rr;
            obj.CreateTime = DateTime.Now;
            WI_LeaveMsgDAL Dal = new WI_LeaveMsgDAL();
            Dal.CreateLeaveMsg(obj);
            ViewBag.msg = "留言成功,请耐心等待管理员的回复哦！";
            WI_LeaveMsgTypeDAL typeDal = new WI_LeaveMsgTypeDAL();
            ViewBag.LeaveTypeList = typeDal.GetAllMsgType();
            return View();
        }


        [OutputCache(Duration = 900, VaryByParam = "*")]
        public ActionResult GetLeaveMsgList(int? page)
        {
            WI_LeaveMsgDAL dal = new WI_LeaveMsgDAL();
            int start = ((page ?? 1) - 1) * 10;
            int PageTotal = 0;
            List<WI_LeaveMsg> list = dal.GetLeaveMsgByAudi(start, 10, out PageTotal);
            PagedList<WI_LeaveMsg> pageList = list.ToPagedList(page ?? 0, 10, PageTotal);
            return PartialView(pageList);
        }
    }
}
